package com.javaee.controller.doctor;

import com.javaee.BeforeBaseController;
import com.javaee.entity.Department;
import com.javaee.entity.Doctor;
import com.javaee.entity.User;
import com.javaee.service.doctor.AuthDoctorService;
import com.javaee.service.doctor.impl.AuthDoctorServiceImpl;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/doctorInfo")
public class doctorInfo extends BeforeBaseController {
    @Autowired
    AuthDoctorService authDoctorService;
    @RequestMapping("/toDoctorInfo")
    public String toDoctorInfo(Model model, HttpSession httpSession){
        Doctor doctor= (Doctor) httpSession.getAttribute("Doctor");
        doctor=authDoctorService.selectADoctor(doctor.getId());
        httpSession.setAttribute("Doctor",doctor);

        List<Department> departments=authDoctorService.selectAllDepartments();
        model.addAttribute("doctor",doctor);
        model.addAttribute("departments",departments);
        return "doctor/doctorInfo";
    }
    @RequestMapping("/toUpdate")
    public String toUpdateUserInfo(HttpSession session, Model model){
    Doctor doctor= (Doctor) session.getAttribute("Doctor");
        List<Department> departments=authDoctorService.selectAllDepartments();
        model.addAttribute("departments",departments);
        model.addAttribute("doctor",doctor);
        return "doctor/updateDoctorInfo";
    }
}
